<template>
    <div>
        <app-head title="修改密码"></app-head>

        <div class="modify">
            <div class="h5form">
                <div class="h5form-item">
                    <input class="h5form-input" v-model="form.oldpwd" placeholder="请输入原始密码" type="password">
                </div>

                <div class="h5form-item">
                    <input class="h5form-input" v-model="form.newpwd" placeholder="请输入新密码" type="password">
                </div>

                <div class="h5form-item">
                    <input class="h5form-input" v-model="form.newpwdAgain" placeholder="请再输入新密码" type="password">
                </div>

                <div class="h5form-submit">
                    <button @click="submit">确定</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import api from '@/api'
export default {
  name: 'modify',
  components: {
  },
  data () {
    return {
      form: {
        oldpwd: '',
        newpwd: '',
        newpwdAgain: ''
      }
    }
  },
  computed: {

  },
  methods: {
    submit () {
      let { oldpwd, newpwd, newpwdAgain } = this.form
      if (!oldpwd || oldpwd.length < 6) {
        this.$tips('旧密码格式不正确！')
        return false
      }
      if (!newpwd || newpwd.length < 6 || newpwdAgain.length < 6) {
        this.$tips('新密码格式不正确！')
        return false
      }
      if (newpwd !== newpwdAgain) {
        this.$tips('两次密码输入不一致！')
        return false
      }
      api.changePwd({
        oldpwd: oldpwd,
        newpwd: newpwd
      }, res => {
        this.$tips(res)
        
        this.$router.push({
          path: '/user',
          query: {
            reload: true,
          }
        })

      }, msg => {
        this.$tips(msg)
      })
    }
  },
  created () {

  }
}
</script>

<style scoped="scoped" lang="scss">

    .modify {
        padding-top: 0.3rem;
    }

</style>
